<%@ page contentType="text/html;charset=utf-8" language="java"
	pageEncoding="UTF-8" import="java.util.Date"%>
<!DOCTYPE html>
<html lang="en">
  <head>
     <%@include file="/WEB-INF/jsp/common/style.jsp"%>
  </head>
  <body>
    <div id="wrap">
    <input type="hidden" id="userId" value="${model.user.id}"> 
   <div class="main_container" id="forms_page">
     	<div class="row-fluid">
          <div class="widget widget-padding span12">
         
            <div class="widget-forms clearfix" style="padding-top:15px">
                <form class="form-horizontal">
                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>用户名:</label>
                    <div class="controls">
                      <input class="w300" type="text" id="userName" placeholder="用户名"  value="${model.user.userName}">
                    
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>员工姓名:</label>
                    <div class="controls">
                      <input class="w300"  id="realName"  type="text" placeholder="姓名"  value="${model.user.realName}">
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label">手机</label>
                    <div class="controls">
                      <input class="w300 tip"   id="mobile"
                       maxlength="11" onkeyup="this.value=this.value.replace(/\D/g,'')" onafterpaste="this.value=this.value.replace(/\D/g,'')" 
                       type="text" placeholder="手机"  value="${model.user.mobile}">
                    </div>
                  </div>
                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>邮箱</label>
                    <div class="controls">
                      <input class="w300 tip"  id="email" type="text" placeholder="邮箱" value="${model.user.email}"> 
                    </div>
                  </div>

                  <div class="control-group">
                    <label class="control-label"><font color="red">*</font>关联角色</label>
                      <div class="controls">
                        <select  id="roleId" class="w300">
                           	<option value="" <c:if test="${model.user.roleId==null}">selected="selected"</c:if>>请选择</option>
					   			<c:forEach items="${model.roles}" var="lo" varStatus="itemStatus">
					               <option value="${lo.id}" <c:if test="${model.user.roleId==lo.id}">selected="selected"</c:if>>${lo.roleName}</option>
					        </c:forEach>  
                        </select>
                     </div>
                  </div>
                 <div class="control-group">
                    <label class="control-label"><font color="red">*</font>职位</label>
                      <div class="controls">
                       <select  id="jobId" class="w300">
                           	<option value="" <c:if test="${model.user.jobId==null}">selected="selected"</c:if>>请选择</option>
					   			<c:forEach items="${model.jobInfos}" var="lo" varStatus="itemStatus">
					               <option value="${lo.id}" <c:if test="${model.user.jobId==lo.id}">selected="selected"</c:if>>${lo.jobName}</option>
					        </c:forEach>  
                        </select>
                     </div>
                  </div>
                  
                </form>
              </div>
           
          </div>
        </div>  
        <div class="row-fluid">
        	<div class="footbtn"> 
        	 <button class="btn btn-primary" type="submit"  onclick="save()">保存</button>
               <button class="btn" type="button" onclick="backIndex()">取消</button>
               </div>
        </div>
     
   	</div>
   	</div>
  </body>
  <script type="text/javascript">
  function save(){
		var postData="&userId=" +$('#userId').val() ;
		
		var userName=$('#userName').val();
		if(userName==''){
			layer.alert('请输入登陆账号');
	    	return;
		}
		postData=postData + "&userName=" + encodeURIComponent(userName);
		
		var mobile=$('#mobile').val();
		postData=postData + "&mobile=" + mobile;
		
		var realName=$('#realName').val();
		if(realName==''){
			layer.alert('请输入姓名');
	    	return;
		}
		postData=postData + "&realName=" + encodeURIComponent(realName);
		
		
		var jobId=$('#jobId').val();
		if(jobId==''){
			layer.alert('请选择职位');
	    	return;
		}
		postData=postData + "&jobId=" + jobId;
		
		var roleId=$('#roleId').val();
		if(roleId==''){
			layer.alert('请选择角色');
	    	return;
		}
		postData=postData + "&roleId=" + roleId;
		
		var email=$('#email').val();
		if(email==''){
			layer.alert('请输入邮箱');
	    	return;
		}
		postData=postData + "&email=" + email;
		
		
		
	    layer.load(1, {shade: [0.5,'#fff']});
	    //alert(postData);
	    $.ajax({
	        type: "POST",
	        url: "saveUser",
	        data: postData,
	        contentType: "application/x-www-form-urlencoded;charset=UTF-8",
	        async: true, // 同步  true 异步。默认是异步
	        dataType: 'json',
	        error: function(resultdata) {
	        	layer.closeAll();
	        },
	        success: function(resultdata) {
	        	layer.closeAll();
	            if(resultdata.returnCode=="0000"){               	
	            	layer.alert('操作成功',{icon: 1}, function(){
	            	 	 parent.editReturn();
	            		//layer.closeAll(); 
	            		 //layer.closeAll();
	            		//window.location.href="${pageContext.request.contextPath}/distrbutor/inventory/index";
	            	});
	            }else{
	            	layer.alert(resultdata.returnMessage);
	            }
	        }
	    });
	}
  function backIndex(){	  
 	 parent.editReturn();
  }
	</script>
</html>
